<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="日期" prop="currentDate">
        <el-date-picker clearable
          v-model="queryParams.currentDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['dispatch:workfaceDayReport:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['dispatch:workfaceDayReport:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['dispatch:workfaceDayReport:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['dispatch:workfaceDayReport:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="workfaceDayReportList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--
      <el-table-column label="矿井名称" align="center" prop="mineName" />
-->
      <el-table-column label="工作面名称" align="center" prop="workfaceName" />
      <el-table-column label="回采队" align="center" prop="miningTeamName" />
      <el-table-column label="日期" align="center" prop="currentDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.currentDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="设计长度" align="center" prop="workLength" />
      <el-table-column label="采煤方法" align="center" prop="miningMethod" />
      <el-table-column label="下井人数" align="center" prop="inMinePersonNum" />
      <el-table-column label="实际产量" align="center" prop="yield" />
      <el-table-column label="计划产量" align="center" prop="dayPlan" />
      <el-table-column label="当日推进" align="center" prop="pdscDayLength" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['dispatch:workfaceDayReport:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['dispatch:workfaceDayReport:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改产量日报对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="日期" prop="currentDate">
          <el-date-picker clearable
            v-model="form.currentDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="工作面" prop="workfaceId">
          <el-select v-model="form.workfaceId" placeholder="请选择工作面" clearable>
            <el-option v-for="item in workfaceOptions" :key="item.workfaceId" :label="item.workFaceName" :value="item.workfaceId" ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="回采队" prop="miningTeamId">
          <el-select v-model="form.miningTeamId" placeholder="请选择回采队" clearable>
            <el-option v-for="item in teamOptions" :key="item.miningTeamId" :label="item.name" :value="item.miningTeamId" ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="设计长度" prop="workLength">
          <el-input v-model="form.workLength" placeholder="请输入设计长度" />
        </el-form-item>
        <el-form-item label="采煤方法" prop="miningMethod">
          <el-input v-model="form.miningMethod" placeholder="请输入采煤方法" />
        </el-form-item>
        <el-form-item label="下井人数" prop="inMinePersonNum">
          <el-input v-model="form.inMinePersonNum" placeholder="请输入下井人数" />
        </el-form-item>
        <el-form-item label="实际产量" prop="yield">
          <el-input v-model="form.yield" placeholder="请输入实际产量" />
        </el-form-item>
        <el-form-item label="计划产量" prop="dayPlan">
          <el-input v-model="form.dayPlan" placeholder="请输入计划产量" />
        </el-form-item>
        <el-form-item label="当日推进" prop="pdscDayLength">
          <el-input v-model="form.pdscDayLength" placeholder="请输入当日推进" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="排序" prop="sort">
          <el-input v-model="form.sort" placeholder="请输入排序" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listWorkfaceDayReport, getWorkfaceDayReport, delWorkfaceDayReport, addWorkfaceDayReport, updateWorkfaceDayReport } from "@/api/dispatch/workfaceDayReport";
import { listWorkfaceInfo} from "@/api/dispatch/workfaceInfo";
import { listTeam} from "@/api/dispatch/team";

export default {
  name: "WorkfaceDayReport",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      teamOptions:[],
      workfaceOptions:[],
      teamOptions:[],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 产量日报表格数据
      workfaceDayReportList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        currentDate: null,
        workfaceId: null,
        miningTeamId: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  mounted() {
    //获取工作面选项
    let workfaceQuery = {pageNum:1,pageSize: 1000,workFaceState:'mining'}
    listWorkfaceInfo(workfaceQuery).then(response => {
      this.workfaceOptions = response.rows;
    });

    //获取回采队选项
    let teamQuery = {pageNum:1,pageSize: 1000}
    listTeam(teamQuery).then(response => {
      this.teamOptions = response.rows;
    });
  },
  methods: {
    /** 查询产量日报列表 */
    getList() {
      this.loading = true;
      listWorkfaceDayReport(this.queryParams).then(response => {
        this.workfaceDayReportList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        reportId: null,
        currentDate: null,
        workfaceId: null,
        workfaceName: null,
        miningTeamId: null,
        miningTeamName: null,
        workLength: null,
        miningMethod: null,
        inMinePersonNum: null,
        yield: null,
        dayPlan: null,
        pdscDayLength: null,
        mineId: null,
        mineName: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        sort: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.reportId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加产量日报";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const reportId = row.reportId || this.ids
      getWorkfaceDayReport(reportId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改产量日报";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.reportId != null) {
            updateWorkfaceDayReport(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addWorkfaceDayReport(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const reportIds = row.reportId || this.ids;
      this.$modal.confirm('是否确认删除产量日报编号为"' + reportIds + '"的数据项？').then(function() {
        return delWorkfaceDayReport(reportIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('dispatch/workfaceDayReport/export', {
        ...this.queryParams
      }, `workfaceDayReport_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
